package com.fang.algorithm.zuo.tree;

import java.util.*;

/**
 * @author lingxiao.fang
 * @Desc 给定一个二叉树，我们在树的节点上安装摄像头。
 * 节点上的每个摄影头都可以监视其父对象、自身及其直接子对象。
 * 计算监控树的所有节点所需的最小摄像头数量。
 * @createTime 2025/3/6 16:14
 */
public class Test05_MinCameraCoverTree {
    private static class TreeNode {
        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }

    public static void main(String[] args) {
        // 1223343
        TreeNode head = new TreeNode(1);
        head.left = new TreeNode(2);
        head.right = new TreeNode(2);
        head.left.left = new TreeNode(3);
        head.left.right = new TreeNode(3);
        head.right.left = new TreeNode(4);
        head.right.right = new TreeNode(3);
        System.out.println(isSymmetric(head));

    }
    private static boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return false;
        }
        if (root.left == null && root.right == null) {
            return true;
        }
        return process(root.left, root.right);
    }

    private static boolean process(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        }
        if (left == null || right == null) {
            return false;
        }
        boolean check1 = process(left.left, right.right);
        boolean check2 = process(left.right, right.left);
        return left.val == right.val && check1 && check2;
    }


}
